<template>
	<view class="main" >
		<view class="title">
			收款码
		</view>
		<view class="content">
			<text class="contentLeft"></text>
			<text class="contentRight"></text>
			<view class="content_title">
				收款码
			</view>
			<view class="content_id">
				扫二维码向我付款
			</view>
			
			
			<view class="content_qrCode">			
				<image :src="qrcode" style="margin: 0 auto;	width: 130px;height: 130px;" ></image>
			</view>
			
			<view class="last_line" >
				收款帐号:{{account}}
			</view>
			<view class="functionList">
			    <view class="function">
					<image src="/static/copy.png" mode=""></image>
			     <text @click="returnClick()">返回</text>
			    </view>
			    <view class="function"  @tap="copyCenter(userData.usdt_address)">
					<image src="/static/copy.png" mode=""></image>
			     <text>保存收款码</text>
			    </view>
			</view>
			
			<view class="remark_text" >
				{{text}}
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	import jvue from '@/libs/jdk/jvue';

export default {
	data() {
		return {
			userData:[],
			app:null,
			qrcode:'',
			balance:'',
			counter:0,
			detailInterval:null,
			text:'',
			query:{}
		};
	},
	onLoad(e) {
		this.query = e;
		this.app = app;
		this.type=	e.type;
		//this.checkChange();
	},
	onShow() {
		var uid = app.uid();
		var that = this;
		
		this.text = "仅可向此地址转入TRC20通道，转入其它通道将无法找回";
		
		api("@/usdt/api/main.php?cmd=getuseraddress&uid="+uid,"get",{}).then(res=>{
			//console.log("getuseraddress:");
			//console.log(res);
			this.getUserInfo();
			
			/*
			api("@/usdt/api/main.php?cmd=user_balance&uid="+uid,"get",{}).then(res=>{
				console.log("user_balance:");
				console.log(res.data.value);
				that.balance = res.data.value;
				
			});
			*/
		});
		
		this.checkUserChange();
	},
	methods: {
		checkUserChange(){
			
			var uid = app.uid();
			api("@/usdt/api/main.php?cmd=refresh_user_usdt_money&uid="+uid,"get",{}).then(res=>{
				console.log("msg:");
				console.log(res.msg);
				if(res.msg!=''){
					app.appShowToast(res.msg, 'none', false, 2000);
				}
				
			});
			
		},
		checkChange(){
			var that = this;
			var detailInterval = setInterval(() => {
				
				this.checkUserChange();
				that.counter++;
				if(that.counter>=3){
					clearInterval(that.detailInterval);
				}
				
			}, 8000)
		},
		getUserInfo(){
			
			// var HTTP_REQUEST_URL = 'http://yhg.zukoo.com.cn';
			getUserInfo().then(res=>{
				this.userData = res.data;
				this.qrcode = HTTP_REQUEST_URL + "/inc/QRcode.php?s=" + this.userData.usdt_address;
				console.log(this.qrcode);
				
			});
			
			
		},
		copyCenter(value){
			//复制文本内容
			value += '';
			console.log('复制内容~~'+value);
			//设置系统剪贴板的内容  提示：API `setClipboardData` is not yet implemented  表示当前并不支持H5 此功能
			uni.setClipboardData({
			    data: value,
			    success: function () {
			        console.log('success--'+value);
			    }
			});
			
		},
		returnClick() {
		
			app.toUrl('/pages/user/assets/money');
		
		}
	}
};
</script>

<style scope=lass>
  @import "qrcode.css";
</style>
